import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import Responder from "./middlewares/response";
import auth from "./routes/auth";
import health from "./routes/health";
import memo from "./routes/memo";
import baseline from "./routes/baseline";
import mood from "./routes/mood";
import { connectMongo } from "./db/mongo";

const app = new Hono().basePath("/api");

app.use(cors());
app.use(logger());

app.route("/auth", auth);
app.route("/health", health);
app.route("/memo", memo);
app.route("/baseline", baseline);
app.route("/mood", mood);

app.onError((err, c) => {
  console.error(err);
  return Responder.fail(err?.message).build(c);
});

app.notFound((c) => {
  return Responder.fail("Api Not Found").setStatusCode(404).build(c);
});

connectMongo().catch(console.error);

export default {
  port: process.env.PORT || 5000,
  fetch: app.fetch,
};
